package com.biovr.backend.security;

import com.biovr.backend.domain.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

public class JwtUser implements UserDetails {
    private final String id;
    private final String username;
    private final String password;
    private  String realName;
    private  String gender;
    private String avater;
    private String phone;
    private String email;
    private Date registerDate;
    private Date lastLogin;
    private String lastLoginIp;
    private Integer loginTimes;
    //学校
    private String schoolId;
    private String schoolName;
    //学生专业
    private Major stuMajor;
    //学生年级
    private Grade stuGrade;
    private Klass stuClass;
    //学号/工号
    private String schoolNum;
    private Department teacherDepartment;
    private  Date  lastPasswordResetDate ;
    private final Collection<? extends GrantedAuthority> authorities;

    public JwtUser(
            String id,
            String username,
            String password,
            String realName,
            String gender,
            String avater,
            String phone,
            String email,
            Date registerDate,
            Date lastLogin,
            String lastLoginIp,
            Integer loginTimes,
            String schoolId,
            String schoolName,
            Major stuMajor,
            Grade stuGrade,
            Klass stuClass,
            String schoolNum,
            Department teacherDepartment,
            Date lastPasswordResetDate,
            Collection<? extends GrantedAuthority> authorities) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.realName=realName;
        this.gender=gender;
        this.avater=avater;
        this.phone=phone;
        this.email=email;
        this.registerDate=registerDate;
        this.lastLogin=lastLogin;
        this.lastLoginIp=lastLoginIp;
        this.loginTimes=loginTimes;
        this.schoolId=schoolId;
        this.schoolName=schoolName;
        this.stuMajor = stuMajor;
        this.stuGrade = stuGrade;
        this.stuClass=stuClass;
        this.schoolNum = schoolNum;
        this.teacherDepartment=teacherDepartment;
        this.email = email;
        this.lastPasswordResetDate = lastPasswordResetDate;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @JsonIgnore
    public String getId() {
        return id;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }

    @JsonIgnore
    public Date getLastPasswordResetDate() {
        return lastPasswordResetDate;
    }
}
